package com.example.covid.Utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置拦截器
 *
 * @author KamenRider
 */
@Configuration
public class MyWebConfig implements WebMvcConfigurer {

  @Autowired
  @Qualifier(value = "loginInterceptor")
  private HandlerInterceptor handlerInterceptor;

  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    InterceptorRegistration interceptorRegistration = registry.addInterceptor(handlerInterceptor);
    //所有请求都会拦截
    interceptorRegistration.addPathPatterns("/**");
    // 放行请求
    interceptorRegistration.excludePathPatterns(
            "/login",
            "/loginIf",
            "/logout",
            "/captcha",
            "/css/**",
            "/js/**",
            "/images/**",
            "/api/**"
    );
    WebMvcConfigurer.super.addInterceptors(registry);
  }
}
